package net.opentsdb.plugin;

import net.opentsdb.auth.Authentication;
import net.opentsdb.core.WriteableDataPointFilterPlugin;
import net.opentsdb.meta.MetaDataCache;
import net.opentsdb.meta.TsuidDelete;
import net.opentsdb.search.SearchPlugin;
import net.opentsdb.tools.StartupPlugin;
import net.opentsdb.tsd.RTPublisher;
import net.opentsdb.tsd.StorageExceptionHandler;
import net.opentsdb.uid.UniqueIdFilterPlugin;

public class TsdbPluginWrapper {

    /** Authentication Plugin to use if configured */
    private Authentication authentication;

    /** Search indexer to use if configured */
    private SearchPlugin search;

    /** Optional Startup Plugin to use if configured */
    private StartupPlugin startup;

    /** Optional real time pulblisher plugin to use if configured */
    private RTPublisher rt_publisher;

    /** Optional plugin for handling meta data caching and updating */
    private MetaDataCache meta_cache;

    /** Plugin for dealing with data points that can't be stored */
    private StorageExceptionHandler storage_exception_handler;

    /** A filter plugin for allowing or blocking time series */
    private WriteableDataPointFilterPlugin ts_filter;

    /** A filter plugin for allowing or blocking UIDs */
    private UniqueIdFilterPlugin uid_filter;

    /** A filter plugin for allowing or blocking UIDs */
    private TsuidDelete tsuidDelete;

    private TsdbPluginLoader loader;

    public TsdbPluginWrapper(TsdbPluginLoader loader){
        this.loader = loader;
        authentication = (Authentication)loader.get(Authentication.class);
        search = (SearchPlugin)loader.get(SearchPlugin.class);
        startup = (StartupPlugin)loader.get(StartupPlugin.class);
        rt_publisher = (RTPublisher)loader.get(RTPublisher.class);
        meta_cache = (MetaDataCache)loader.get(MetaDataCache.class);
        storage_exception_handler = (StorageExceptionHandler)loader.get(StorageExceptionHandler.class);
        ts_filter = (WriteableDataPointFilterPlugin)loader.get(WriteableDataPointFilterPlugin.class);
        uid_filter = (UniqueIdFilterPlugin)loader.get(UniqueIdFilterPlugin.class);
        tsuidDelete = (TsuidDelete)loader.get(TsuidDelete.class);
    }

    public Authentication getAuthentication() {
        return authentication;
    }

    public SearchPlugin getSearch() {
        return search;
    }

    public StartupPlugin getStartup() {
        return startup;
    }

    public RTPublisher getRt_publisher() {
        return rt_publisher;
    }

    public MetaDataCache getMeta_cache() {
        return meta_cache;
    }

    public StorageExceptionHandler getStorage_exception_handler() {
        return storage_exception_handler;
    }

    public WriteableDataPointFilterPlugin getTs_filter() {
        return ts_filter;
    }

    public UniqueIdFilterPlugin getUid_filter() {
        return uid_filter;
    }

    public final void setStartup(final StartupPlugin startup){
        this.startup = startup;
    }

    public TsuidDelete getTsuidDelete() {
        return tsuidDelete;
    }
}
